import { createServer } from 'vite'
import type { CONFIG } from '../../types/config'
import { RUN_TEMPLATE_PATH } from '../uitls'

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default async function start (options: Required<CONFIG>) {
  const { devServer } = options
  const server = await createServer({
    configFile: false,
    root: RUN_TEMPLATE_PATH,
    server: {
      port: devServer.port,
      host: '0.0.0.0'
    },
    plugins: [
      vue(),
      vueJsx()
    ]
  })

  await server.listen()
  server.printUrls()
}
